package com.jichangxiu.system.action;

import com.jichangxiu.common.entity.vo.PageResult;
import com.jichangxiu.system.entity.dto.edit.EditSysInfo;
import com.jichangxiu.system.entity.dto.query.QuerySysInfo;
import com.jichangxiu.system.entity.vo.SysInfoVo;
import com.jichangxiu.system.service.SysInfoService;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.common.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * SysInfoAction:
 *
 * @author JiChangXiu
 * @create 2024-06-28 13:44:24
 */
@Slf4j
@Rest("/system/info")
@Tag(name = "系统登录信息控制器")
public class SysInfoAction extends BaseAction {

    @Resource
    private SysInfoService sysInfoService;

    /**
     * 修改系统登录信息
     *
     * @param editSysInfo 修改系统登录信息视图对象
     * @return 是否成功
     */
    @Put
    @Limit
    @Repeat
    @Log(remark = "修改系统登录信息")
    @Operation(summary = "修改系统登录信息")
    @PreAuthorize("@jcx.hasPower('system:info:edit')")
    public String edit(@RequestBody EditSysInfo editSysInfo) {
        return str(sysInfoService.edit(editSysInfo));
    }

    /**
     * 根据主键查询系统登录信息
     *
     * @param id       系统登录信息主键
     * @param isExtend 是否扩展
     * @return 系统登录信息详情
     */
    @Get("/{id}")
    @Operation(summary = "根据主键查询系统登录信息")
    @PreAuthorize("@jcx.hasPower('system:info:info')")
    public SysInfoVo info(@PathVariable("id") @NotBlank(message = "主键不能为空") String id, @RequestParam(value = "isExtend", required = false, defaultValue = "false") Boolean isExtend) {
        return sysInfoService.info(id, isExtend);
    }

    /**
     * （可分页）查询系统登录信息列表
     *
     * @param querySysInfo 查询视图对象
     * @return （分页）系统登录信息列表
     */
    @Get("/lists")
    @Operation(summary = "（可分页）查询系统登录信息列表")
    @PreAuthorize("@jcx.hasPower('system:info:lists')")
    public PageResult lists(@ParameterObject QuerySysInfo querySysInfo) {
        return pageResult(sysInfoService.lists(querySysInfo));
    }

}